package com.meida.module.bus.provider.controller;

import com.alibaba.fastjson.util.TypeUtils;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.springmvc.base.BaseController;
import com.meida.common.utils.FlymeUtils;
import com.meida.module.bus.client.entity.BusPurchaseDetails;
import com.meida.module.bus.client.entity.BusVersion;
import com.meida.module.bus.provider.service.BusPurchaseDetailsService;
import com.meida.module.bus.provider.service.BusVersionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/bus/purchasedetail/")
public class BusPurchaseDetailController extends BaseController<BusPurchaseDetailsService, BusPurchaseDetails> {
    @Autowired
 private BusVersionService busVersionService;
    /**
     * 查询采购申请记录页面
     * @param params
     * @return
     */
    @ApiOperation(value = "采购申请详情-分页列表", notes = "采购申请详情")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params)
    {

        BusVersion lastVersion=busVersionService.getLatestVersion(Long.parseLong(params.get("projectId").toString()),1);
        if(FlymeUtils.isNotEmpty(lastVersion)){
            String bigVersion=lastVersion.getBigVersion();
            Integer bigVal= TypeUtils.castToInt(bigVersion);
            if(bigVal==100){
                params.put("versionType","1");
            }else{
                params.put("versionType","2");
            }
        }
        return bizService.pageList(params);
    }
}
